<!DOCTYPE html>
<html lang="zh-cn"><head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    
    <link href="/css/bootstrap.min.css" rel="stylesheet">
    <link href="/css/main.css" rel="stylesheet">

    <link rel="shortcut icon" type="image/x-icon" href="/img/favicon.ico" />

    <title>samba服务器配置和使用 | wiseAI的小站</title>
</head><body><div class="container-fluid">
    <nav class="navbar fixed-top navbar-expand-sm navbar-dark bg-dark">
        <div class="container-fluid">
            <a class="navbar-brand" href="/">
                <img src="/img/favicon.ico" alt="" width="30" height="24" class="d-inline-block align-text-top">
                wiseAI的小站
            </a>
            <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
                <span class="navbar-toggler-icon"></span>
            </button>
            <div class="collapse navbar-collapse" id="navbarSupportedContent">
                <ul class="navbar-nav me-auto mb-2 mb-lg-0">
                    
                    <li class="nav-item">
                        <a  class="nav-link"   href="/articles/">文章</a>
                    </li>
                    
                    <li class="nav-item">
                        <a  class="nav-link"   href="/categories/">分类</a>
                    </li>
                    
                    <li class="nav-item">
                        <a  class="nav-link"   href="/tags/">关键字</a>
                    </li>
                    
                    <li class="nav-item">
                        <a  class="nav-link"   href="/post/golang/">golang编程</a>
                    </li>
                    
                    <li class="nav-item">
                        <a  class="nav-link"   href="/about/">关于</a>
                    </li>
                    
                </ul>
                <form class="d-flex">
                    <input id="search-query" class="form-control me-2" type="search" placeholder="Search for anything..." aria-label="Search">
                </form>
            </div>
        </div>
    </nav>
</div>




<div id="content">
<div class="container article">
	<h1>samba服务器配置和使用</h1>
	<div class="post-meta">
		<div>
			
			
			By wiseai | 2022-06-20 | 2 minutes
		</div>
		<div class="tags">
			
			<a class="btn btn-light links btn-sm" href="/tags/windows%E5%85%B1%E4%BA%AB/">windows共享</a>
			
			<a class="btn btn-light links btn-sm" href="/tags/samba/">samba</a>
			
		</div>
	</div>
	<div>
		<div class="article-post">
			<p>安装：</p>
<p><code>#dnf install samba</code></p>
<p>端口：</p>
<p>管理工作组：UDP137，138</p>
<p>共享数据：TCP139，445（不一定存在）</p>
<p>启动服务：</p>
<p><code>#systemctl start  smb</code></p>
<p><code>#systemctl enable smb</code></p>
<p>配置文件（/etc/samba/smb.conf）:</p>
<p>1.先设定好服务器整体环境方面的参数</p>
<p>[global]</p>
<p>config file = /etc/samba/conf/smb.conf.%m</p>
<p>说明：config file可以让你使用另一个配置文件来覆盖缺省的配置文件。如果文件 不存在，则该项无效。这个参数很有用，可以使得samba配置更灵活，可以让一台samba服务器模拟多台不同配置的服务器。比如，你想让PC1（主机 名）这台电脑在访问Samba Server时使用它自己的配置文件，那么先在/etc/samba/host/下为PC1配置一个名为smb.conf.pc1的文件，然后在 smb.conf中加入：config file = /etc/samba/conf/smb.conf.%m。这样当PC1请求连接Samba Server时，smb.conf.%m就被替换成smb.conf.pc1。这样，对于PC1来说，它所使用的Samba服务就是由 smb.conf.pc1定义的，而其他机器访问Samba Server则还是应用smb.conf。</p>
<pre tabindex="0"><code>#用户组

workgroup = mygroup

#欢迎信息

server string = Samba Server Version %v

#加密

security = user

#使用TDB 数据库格式

passdb backend = tdbsam

#不加载打印机

load printers = no

#共享名

[homes]

#说明

comment = Home Directories

#除了使用者自己外,不可被其他人浏览

browseable = no

#挂载后可擦写此分享

writable = yes

#建立档案的权限为 664

create mode = 0664

#建立目录的权限为 775

directory mode = 0775

#指定允许访问该共享资源的用户&amp;&amp;多个用户或者组中间用逗号隔开，如果要加入一个组就用&#34;@组名&#34;表示,%s表示代替前一个[]里的内容

valid users = %S

valid users = MYDOMAIN\%S

[share]

comment = Public Stuff

#实际的 Linux 上面的目录位置

path = /home/samba

#用来指定该共享的管理员（对该共享具有完全控制权限）

admin users = admin

#指定允许访问该共享资源的用户或者组

valid users = share,@share

#指定不允许访问该共享资源的用户

invalid users = guest

#除了使用者自己外,不可被其他人浏览

browseable = no

#指定可以在该共享下写入文件的用户

write list = share,@share

#指定该共享是否允许guest账户访问

public = no

#指定该共享路径是否可写

writable = yes

#可以在该共享下写入文件的用户和组

write list = share,@share
</code></pre><ol start="2">
<li>用 testparm 查阅 smb.conf 的语法设定正确性</li>
</ol>
<p>3.建立目录</p>
<p><code>#mkdir /home/project</code></p>
<p><code>#chmod 2770 /home/project</code></p>
<p>最后改变目录用户或者组属性</p>
<p>4.设定可使用 Samba 的用户账号与密码</p>
<p><code>#useradd -M -s /sbin/nologin -d /dev/null -G user1 share</code></p>
<p>使用 pdbedit 指令功能</p>
<p><code># pdbedit -L [-vw]        &lt;==单纯的察看帐户信息</code></p>
<p><code># pdbedit -a'-r'-x -u 账号       &lt;==新增/修改/删除账号</code></p>
<p><code># pdbedit -a -m -u 机器账号       &lt;==与 PDC 有关的机器码</code></p>
<p>选项与参数:</p>
<p>-L :列出目前在数据库当中的账号与 UID 等相关信息;</p>
<p>-v :需要搭配 -L 来执行,可列出更多的讯息,包括家目录等数据;</p>
<p>-w :需要搭配 -L 来执行,使用旧版的 smbpasswd 格式来显示数据;</p>
<p>-a :新增一个可使用 Samba 的账号,后面的账号需要在 /etc/passwd 内存在者;</p>
<p>-r :修改一个账号的相关信息,需搭配很多特殊参数,请 man pdbedit;</p>
<p>-x :删除一个可使用 Samba 的账号,可先用 -L 找到账号后再删除;</p>
<p>-m :后面接的是机器的代码 (machine account),与 domain model 有关!</p>
<p><code># pdbedit -a -u share</code></p>
<p>修改密码:</p>
<p><code>#smbpasswd share</code></p>
<p>5.查看分享资源</p>
<p><code>#smbclient -L [//主机或 IP] [-U 使用者账号]</code></p>
<p>6.挂载</p>
<p><code>#mount -t cifs //127.0.0.1/share /mnt -o username=share,password=123456</code></p>
<p>7.smbstatus:观察 SAMBA 的状态</p>
<p><code># smbstatus [-pS] [-u username]</code></p>
<p>选项与参数:</p>
<p>-p :列出已经使用 SAMBA 联机的程序 PID ;</p>
<p>-S :列出已经被使用的资源共享状态;</p>
<p>-u :只列出某个用户相关的分享数据</p>
<p>8.SELinux设置</p>
<p><code>#允许共享Home目录</code></p>
<p><code>setsebool -P samba_enable_home_dirs on</code></p>
<p>#更改SELinux用户</p>
<p><code>chcon -t samba_share_t /path/to/directory</code></p>

		</div>
	</div>
</div>


<div class="container">
    
    <div class="row">
        
        <div class="col-5">
            <a class="page-link link-dark text-end dh" href="/post/ssh%E5%8A%A0%E5%AF%86%E7%AE%97%E6%B3%95%E7%9A%84%E5%90%AF%E7%94%A8%E7%A6%81%E7%94%A8%E6%96%B9%E6%B3%95/">
                <h5>前一篇</h5><br>
                ssh加密算法的启用禁用方法
            </a>            
        </div>
        
        <div class="col-2">
        </div>
        
        <div class="col-5">
            <a class="page-link link-dark text-start dh" href="/post/php%E6%88%AA%E5%8F%96%E4%B8%AD%E6%96%87%E5%AD%97%E7%AC%A6%E4%B8%B2%E4%B9%B1%E7%A0%81%E9%97%AE%E9%A2%98/">
                <h5>后一篇</h5><br>
                php截取中文字符串乱码问题
            </a>            
        </div>
        
    </div>
    
</div>

        </div><br><br>
<footer class="container">
    <h2>友情链接</h2>
    <hr>
    <nav class="nav nav-pills flex-column flex-sm-row">
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://wiseai.gitee.io/pages/gnzg/index.html" target="_blank">孤鸟之歌</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://wiseai.gitee.io/pages/mm/index.html" target="_blank">生成随机字符</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://wiseai.gitee.io/pages/md/index.html" target="_blank">MarkDown</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://gitee.com/" target="_blank">Gitee</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://github.com/" target="_blank">Github</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://www.aliyun.com/" target="_blank">阿里云</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://cloud.tencent.com/" target="_blank">腾讯云</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://www.oschina.net/" target="_blank">OSCHINA开源中国</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://gitee.com/wiseai/the-way-to-go_ZH_CN/blob/master/eBook/directory.md" target="_blank">the way to go</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://topgoer.com/" target="_blank">golang文档</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://goframe.org/display/gf" target="_blank">GoFrame</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://www.aliyundrive.com/" target="_blank">阿里云盘</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://cn.vuejs.org/" target="_blank">vue3文档</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://element-plus.gitee.io/zh-CN/" target="_blank">element-plus文档</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://www.runoob.com/vue3/vue3-tutorial.html" target="_blank">vue3菜鸟教程</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://v5.bootcss.com/" target="_blank">bootstrap v5 中文文档</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://www.bootstrap.cn/" target="_blank">bootstrap文档</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://caddy2.dengxiaolong.com/docs/" target="_blank">caddy中文教程</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://www.58pic.com/" target="_blank">千图</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://ifonts.com/" target="_blank">iFonts</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://marketing.qiniu.com/" target="_blank">七牛云</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://www.ixigua.com/" target="_blank">西瓜视频</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://wiseai.gitee.io/pages/yugang/index.html" target="_blank">鱼缸计算</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://justcc.mengkang.net/#/" target="_blank">C语言JustCC</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://wiseai.gitee.io/pages/pptist/" target="_blank">PPTist</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="/index.xml" target="_blank">RSS</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://www.kancloud.cn/idcpj/python/418553" target="_blank">参考资料</a>
        
    </nav>

    <div class="copyright text-center">
      <span class="power-by">
        Powered by <a class="links" href="https://gohugo.io" target="_blank">Hugo</a>
    </span>
    <span>|</span>
    <span>
        Theme - <a class="links" href="https://github.com/wiseai-go/blog-hugo" target="_blank">WiseAI</a>
    </span>
    <br>
    <span class="copyright-year">
        &copy;
        
        2017 -
        2023<span>
            陇ICP备15000157号
            
        </span></span>

</div>
</footer>
<script src="/js/bootstrap.bundle.min.js"></script>


</body>
</html>
